'''
#Coding: utf-8
#Project: online-exam
#Author: rtf
#Time: 2022-07-27 18:39:10
#FileName: student.py
#Softwar: PyCharm
'''


from trump.query import get_item, get_items, get_table_header, modify_item
from trump.utils import ok, fail
from trump.decorators import table_headers
from utils.params_validate_decorator import validate_params
from funcs.user_info import get_uesr_info

difficulty_level = {"simple": "简单", "general": "一般", "complex": "复杂"}
subject_type = {"single": "单选题", "multiple": "多选题", "questions": "问答题"}


async def post(app, request):
    pass


async def put(app, request, id):
    pass


async def ls(app, request):
    pass


async def post_ls(app, request, data):
    course = await get_items(app.ctx.pool, "course")
    for i in data:
        for x in course:
            if i.get("course_code") == x.get("code"):
                i["course_name"] = x.get("name")
        i["subject_type_name"] = subject_type.get(i.get("subject_type"))
        i["difficulty_level_name"] = difficulty_level.get(i.get("difficulty_level"))


async def get(app, request, id):
    pass


async def post_get(app, request, data, id):
    course = await get_item(app.ctx.pool, "course", data.get("course_code"), column="code")
    data["course_name"] = course.get("name") if course else None
    data["subject_type_name"] = subject_type.get(data.get("subject_type"))
    data["difficulty_level_name"] = difficulty_level.get(data.get("difficulty_level"))


async def delete(app, request, id):
    pass